package com.lianwei.service.impl;

import com.lianwei.service.MailService;
import com.lianwei.util.CheckUtil;
import com.lianwei.util.CommonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/*
 *@ClassName MailServiceImpl
 *@Description 邮件服务
 *@Author Kuiwen.Sun
 *@Date 2022/1/11 15:42
 *@Version 1.0
 */
@Slf4j
@Service
public class MailServiceImpl implements MailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.from}")
    private String from;


    @Override
    public void sendEmail(String emailAddress, String subject, String content) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo(emailAddress);
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setText(content);
        System.out.println(simpleMailMessage.toString());
        System.out.println(javaMailSender.toString());
        javaMailSender.send(simpleMailMessage);
        log.info("邮件发送成功",simpleMailMessage.toString());
    }
}
